/*
 * Copyright (c)  2015~2020, xforceplus
 * All rights reserved.
 * Project:datacare-orm
 * Id: MapperConfig.java   2020-09-29 21-38-55
 * Author: Evan
 */
package cn.datacare.orm.mapper.builder;

import cn.datacare.orm.mapper.BaseMapper;
import cn.datacare.orm.mapper.MapperInvoke;
import cn.datacare.orm.mapper.MethodDesc;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: 2015~2020
 * </p>
 * <p>
 * Company/Department: xforceplus
 * </p>
 *
 * @author Evan
 * <b>Creation Time:</b> 2020-09-29 21-38-55
 * @since V1.0
 */
public final class MapperConfig {
    private final MapperConfigBuilder builder = new MapperConfigBuilder();

    private Map<Class, MapperConfigBuilder> mapperConfigBuilderMap = new HashMap<>();

    public MapperConfig(Class c) {
        this.mapperConfigBuilderMap.put(c, builder);
        this.mapperConfigBuilderMap.put(BaseMapper.class, MapperInvokeDataConfig.BASE_MAPPER_BUILDER);
    }

    public MapperConfig() {
        this.mapperConfigBuilderMap.put(BaseMapper.class, MapperInvokeDataConfig.BASE_MAPPER_BUILDER);
    }

    public MethodDesc createMethodDesc() {
        return builder.methodDescBuilder.create();
    }

    public MapperConfigBuilder getBuilder() {
        return builder;
    }

    /**
     * 根据接口, 接口方法名, 获取对应的处理类
     *
     * @param c      接口
     * @param method 接口方法名
     * @return Ami 处理类
     */
    public MapperInvoke getAmi(Class c, String method) {
        MapperConfigBuilder builder = this.mapperConfigBuilderMap.get(c);
        if(builder==null){
            return null;
        }else{
            return builder.getAmi(method);
        }

    }
}
